package lws.com.liwushuo.adapter.bangdan;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;
import java.util.Map;

import lws.com.liwushuo.R;
import lws.com.liwushuo.bean.bangdan.Bangdan_danpin2Bean;
import lws.com.liwushuo.view.fragment.bangdan.BangdanerActivity;

/**
 * Created by YaYun on 2016/10/16.
 */

public class Bangdan_danpin2_Adapter extends BaseAdapter {
    private Context context;
    private Map<Integer,List<Bangdan_danpin2Bean.DataBean.RecommendItemsBean>> map;

    public Bangdan_danpin2_Adapter(Map<Integer, List<Bangdan_danpin2Bean.DataBean.RecommendItemsBean>> map) {
        this.map = map;
    }

    public Map<Integer, List<Bangdan_danpin2Bean.DataBean.RecommendItemsBean>> getMap() {
        return map;
    }

    public void setMap(Map<Integer, List<Bangdan_danpin2Bean.DataBean.RecommendItemsBean>> map) {
        this.map = map;
    }

    @Override
    public int getCount() {
        return map.size();
    }

    @Override
    public Object getItem(int position) {
        return map.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        context = parent.getContext();
        MyHolder1 myHolder1 = null;
        final List<Bangdan_danpin2Bean.DataBean.RecommendItemsBean> list = map.get(position);
            if(convertView == null){
                myHolder1 = new MyHolder1();
                convertView = LayoutInflater.from(context).inflate(R.layout.bangdan_danpin_item3,null);
                myHolder1.cover_image_url = (SimpleDraweeView) convertView.findViewById(R.id.danpin_item3_cover_image_url);
                myHolder1.item3_name = (TextView) convertView.findViewById(R.id.danpin_item3_name);
                myHolder1.item3_price = (TextView) convertView.findViewById(R.id.danpin_item3_price);
                myHolder1.item3_layout1 = (LinearLayout) convertView.findViewById(R.id.danpin_item3_layout1);
                myHolder1.cover_image_url2 = (SimpleDraweeView) convertView.findViewById(R.id.danpin_item3_cover_image_url2);
                myHolder1.item3_name2 = (TextView) convertView.findViewById(R.id.danpin_item3_name2);
                myHolder1.item3_price2 = (TextView) convertView.findViewById(R.id.danpin_item3_price2);
                myHolder1.item3_layout2 = (LinearLayout) convertView.findViewById(R.id.danpin_item3_layout2);
                myHolder1.item3_layout1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();
                        bundle.putInt("id",list.get(0).getId());
                        bundle.putString("purchase_url",list.get(0).getPurchase_url());
                        intent.putExtras(bundle);
                        intent.setClass(v.getContext(),BangdanerActivity.class);
                        v.getContext().startActivity(intent);
                    }
                });
                myHolder1.item3_layout2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();
                        bundle.putInt("id",list.get(1).getId());
                        bundle.putString("purchase_url",list.get(1).getPurchase_url());
                        intent.putExtras(bundle);
                        intent.setClass(v.getContext(),BangdanerActivity.class);
                       v.getContext().startActivity(intent);
                    }
                });
                convertView.setTag(myHolder1);
            }
            myHolder1 = (MyHolder1) convertView.getTag();
            myHolder1.cover_image_url.setImageURI(list.get(0).getCover_image_url());
            myHolder1.item3_name.setText(list.get(0).getName());
            myHolder1.item3_price.setText(list.get(0).getPrice());
            myHolder1.cover_image_url2.setImageURI(list.get(1).getCover_image_url());
            myHolder1.item3_name2.setText(list.get(1).getName());
            myHolder1.item3_price2.setText(list.get(1).getPrice());
            return convertView;
    }

    class MyHolder1{
        SimpleDraweeView cover_image_url2,cover_image_url;
        TextView item3_name,item3_name2,item3_price,item3_price2;
        LinearLayout item3_layout1,item3_layout2;
    }
}
